﻿using System;
using System.Linq;
using LINQPad.Extensibility.DataContext;
using LINQPad.OpenAccess.Data;
using LINQPad.OpenAccess.Settings;
using Telerik.OpenAccess;
using Telerik.OpenAccess.Metadata;

namespace LINQPad.OpenAccess.Services
{
    /// <summary>
    /// Backend service.
    /// </summary>
    public interface IBackendService
    {
        /// <summary>
        /// Creates the default configuration for the specified provider.
        /// </summary>
        /// <param name="providerName">Name of the provider.</param>
        /// <returns>
        /// The default configuration.
        /// </returns>
        BackendConfiguration CreateDefaultConfigurationForProvider( string providerName );
        /// <summary>
        /// Creates the default configuration for the specified backend.
        /// </summary>
        /// <param name="backend">The backend.</param>
        /// <param name="providerName">Name of the provider.</param>
        /// <returns>
        /// The default configuration.
        /// </returns>
        BackendConfiguration CreateDefaultConfigurationForBackend( Backend backend, string providerName = null );
        /// <summary>
        /// Gets the backend configuration.
        /// </summary>
        /// <param name="backendSettings">The backend settings.</param>
        /// <param name="databaseInfo">The database info.</param>
        /// <returns></returns>
        BackendConfiguration GetBackendConfiguration( BackendSettings backendSettings, IDatabaseInfo databaseInfo );
        /// <summary>
        /// Gets the backend - provider map.
        /// </summary>
        /// <returns>
        /// The backend provider map.
        /// </returns>
        ILookup<Backend, BackendProviderMapping> GetBackendProviderMap( );
        /// <summary>
        /// Gets the provider mappings for the specified backend.
        /// </summary>
        /// <param name="backend">The backend.</param>
        /// <returns>
        /// The provider mappings.
        /// </returns>
        BackendProviderMapping[] GetProviderMappingsForBackend( Backend backend );
        /// <summary>
        /// Gets the supported backends.
        /// </summary>
        /// <returns>
        /// The supported backends.
        /// </returns>
        Backend[] GetSupportedBackends( );
        /// <summary>
        /// Determines whether the specified backend is supported.
        /// </summary>
        /// <param name="backend">The backend.</param>
        /// <returns>
        ///   <c>true</c> if the backend is supported; otherwise, <c>false</c>.
        /// </returns>
        bool IsBackendSupported( Backend backend );
        /// <summary>
        /// Tries to get the backend from it's configuration name.
        /// </summary>
        /// <param name="backendConfigName">Configuration name of the backend.</param>
        /// <param name="backend">The backend.</param>
        /// <returns>
        ///   <c>true</c> on success; otherwise, <c>false</c>.
        /// </returns>
        bool TryGetBackendFromConfigurationName( string backendConfigName, out Backend backend );
        /// <summary>
        /// Tries to get the default provider for the specified backend.
        /// </summary>
        /// <param name="backend">The backend.</param>
        /// <param name="defaultProviderName">Default name of the provider.</param>
        /// <returns>
        ///   <c>true</c> on success; otherwise, <c>false</c>.
        /// </returns>
        bool TryGetDefaultProviderForBackend( Backend backend, out string defaultProviderName );
    }
}
